package com.local.carousel.service.impl;

import com.local.carousel.mapper.CarouselMapper;
import com.local.carousel.pojo.Carousel;
import com.local.carousel.service.CarouselService;
import com.local.common.util.PageResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarouselServiceImpl implements CarouselService {

    @Autowired
    private CarouselMapper carouselMapper;

    @Override
    public PageResultUtil<Carousel> getCarouselPage(Integer page, Integer limit, String sort, String order, Integer isDeleted) {
        Integer start = (page - 1) * limit;
        List<Carousel> carousels = carouselMapper.findCarouselList(start, limit, sort, order, isDeleted);
        int total = carouselMapper.getTotalCarousels(isDeleted);
        PageResultUtil<Carousel> pageResult = new PageResultUtil<>(carousels, total, limit, page);
        return pageResult;
    }

    /**
     * 新增
     * @param carousel
     * @return
     */
    @Override
    public Integer save(Carousel carousel) {
        return carouselMapper.save(carousel);
    }

    /**
     * 根据id查询轮播图片数据
     * @param id
     * @return
     */
    @Override
    public Carousel getById(Integer id) {
        return carouselMapper.getById(id);
    }


    /**
     * 修改保存
     * @param carousel
     * @return
     */
    @Override
    public Integer update(Carousel carousel) {
        return carouselMapper.update(carousel);
    }

    /**
     * 删除，支持批量删除
     * @param ids
     * @return
     */
    @Override
    public Integer deleteByIds(Integer[] ids, Integer updateUserId, String time) {
        return carouselMapper.deleteByIds(ids, updateUserId, time);
    }


    /**
     * 查询轮播图列表
     * @return
     */
    @Override
    public List<Carousel> getCarouselList() {
        return carouselMapper.findCarouselList(null, null, "carousel_rank", "asc", 0);
    }
}
